export const callout = {
  data() {
    return {
      isHandle: false, // 判断是否是手动拨出
      flag: 0,
    }
  },
  methods: {
    //只有回访才是1
    async  callout(phone, flag = 0) {
      if(websocket.state === 0){
        this.$toast({
          message:'请先建立连接！'
        })
        return
      }
      const isHangup = this.$store.getters.isHangup
      // if(!isHangup){
      //   this.$toast({
      //     message:'请稍后再拨打，还未完整挂机！'
      //   })
      //   return
      // }
      let {
          id,
          usertel,
          userGroupId
        } = this.$store.getters.getUserInfo
      const baseUrl = window.ipurl
      // usertel = 20102
      // usertel = 20132
      let daida = this.$store.getters.daida
      let daidaId = daida ? daida.id : ''
      try{
        const {data} = await this.$get(this,{
          api:'getWOriginate',
          data: {
            Extension:usertel.toString(),
            phone,
            flag,
            //yhm:usertel,
            adminid: id,
            groupId: userGroupId,
            //userid:0,,
            id:daidaId
          }
        },baseUrl)
       
        if(data.state === 0){
          this.$toast({
            message:'IP电话已连接'
          })
          return
        }
        if(data.message){
          this.$warn(data.message)
        }
      }catch(e){
        this.$warn('系统接口getWOriginate.do报错')
      }
    }
  }
}

export const utils = {
  methods: {
    _dateFormat(date, fmt) {
      const o = {
        "M+": date.getMonth() + 1, //月份
        "d+": date.getDate(), //日
        "h+": date.getHours(), //小时
        "m+": date.getMinutes(), //分
        "s+": date.getSeconds(), //秒
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds() //毫秒
      }
      if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
      for (let k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
      }
      return fmt;
    },
    _isEmptyObject(o) {
      return Object.prototype.toString.call(o) === '[object Object]' && Object.keys(o).length === 0 ? true : false
    },
  }
}
